package com.gws.juc;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * 四大函数接口
 * @author gws
 *
 */
public class FourFuntionDemo {
	public static void main(String[] args) {
		//1.Function<T,R>函数型接口   一个输入参数，一个输出参数
		/*Function<String, Integer> fun = new Function<String, Integer>() {
			@Override
			public Integer apply(String t) {
				
				return t.length();
			}
		};
		*/
		Function<String, Integer> fun = s -> {return s.length();};
		System.out.println(fun.apply("abcd"));
		//2.Predicate<T>断定型接口 一个输入参数，返回boolean类型
		/*Predicate<Integer> pre = new Predicate<Integer>() {
			
			@Override
			public boolean test(Integer t) {
				return t>2;
			}
		};*/
		Predicate<Integer> pre = t -> {return t>2;};
		System.out.println(pre.test(4));
		
		//3.Consumer<T>消费型接口 一个输入参数，无返回类型
		/*Consumer<String> con = new Consumer<String>() {
			
			@Override
			public void accept(String t) {
				System.out.println(t);
				
			}
		};*/
		Consumer<String> con = t -> {System.out.println(t);};
		con.accept("你好");
		
		//4.供给型接口 无参数，有返回值
		/*Supplier<String> sup = new Supplier<String>() {
			
			@Override
			public String get() {
				return "哈哈哈";
			}
		};*/
		Supplier<String> sup = () -> {return "哈哈哈";};
		System.out.println(sup.get());
		
		
	}

}
